package com.lagou.edu.service;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * @author stevejson
 */
public interface IUserService {
    public final static String TOKEN = "token";
    /**
     * 注册接口
     * @param email email
     * @param password ps
     * @param code code
     * @param response res
     * @return success
     */
    public boolean register(HttpServletResponse response, String email, String password, String code);

    /**
     * 是否注册
     * @param email em
     * @return success
     */
    public boolean isRegistered(String email);

    /**
     * 登录
     * @param email em
     * @param password ps
     * @param response res
     * @return 邮箱地址
     */
    public String login(HttpServletResponse response, String email, String password);

    /**
     * 根据token查询邮箱
     * @param token token
     * @return 邮箱
     */
    public String info(String token);

    /**
     * response 添加key value
     * @param response response
     * @param key  key
     * @param value value
     */
    public static void addCookie(HttpServletResponse response, String key, String value){
        Cookie cookie = new Cookie(key, value);
        // 设置存在时间为5分钟
        cookie.setMaxAge(5 * 60);
        // 设置作用域
        cookie.setPath("/");
        response.addCookie(cookie);
        System.out.println("设置cookie"+key+":"+value);
    }
}
